<?php
import('Db.Query');
import('Db.Connection');
import('Psg.Core');
import('Psg.Teryt');

if (PSG_CURUSRROLE == "global") {
    $WhereStatement = Db\Operators::Create()->C('state')->O('=')->C('state');
} else {
    $usrState = Psg\Core::getUserInfo(PSG_CURUSREMAIL)['id_woj'];
    $WhereStatement = Db\Operators::Create()->C('state')->O('=')->V($usrState);
}

$Query = \Db\Query::Create('registrations')->Select()->Where($WhereStatement);

$Result = Db\Connection::Open()->Query($Query);
?>
<h1>Rejestracje</h1>
<?php if (count($Result) > 0): ?>
    <table border="1" style="width: 100%;">
        <thead style="background-color: #cccccc">
            <tr>
                <td>Email</td>
                <td>Nick</td>
                <td>Województwo</td>
                <td>Miasto</td>
                <td>Data rejestracji</td>
                <td colspan="2">Akcja</td>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($Result as $id => $vars): ?>
            <form action="<?= Url::site('forms') ?>" method="post">
                <input type="hidden" name="email" value="<?= $vars['email'] ?>"/>
                <input type="hidden" name="_ACTION" value="registrations"/>
                <input type="hidden" name="_EXECUTE" value="performReg"/>
                <tr>
                    <td><?= $vars['email'] ?></td>
                    <td><?= $vars['nick'] ?></td>
                    <td><?= Psg\Teryt::getStateName($vars['state']) ?></td>
                    <td><?= Psg\Teryt::getCityName($vars['city']) ?></td>
                    <td><?= $vars['dateofreg'] ?></td>
                    <td style="border: none; text-align: center;"><button type="submit" name="btnAccept">Akceptuj</button></td>
                    <td style="border: none; text-align: center;"><button type="submit" name="btnRefuse">Odrzuć</button></td>
                </tr>
            </form>
        <?php endforeach; ?>
    </tbody>
    </table>
<?php else: ?>
    <p>Brak rejestracji</p>
<?php endif; ?>
